package com.miaowang.salad.jobqueue;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.miaowang.salad.data.OkHttpResponseData;
import com.miaowang.salad.net.OkHttpUtils;
import com.miaowang.salad.net.UrlUtils;
import com.path.android.jobqueue.Job;
import com.path.android.jobqueue.Params;
import com.path.android.jobqueue.RetryConstraint;

import de.greenrobot.event.EventBus;

/**
 * 获取历史任务列表
 * @author weihe
 *
 */
public class GetHistoryServiceListJob extends Job {

	public GetHistoryServiceListJob() {
		super(new Params(JobQueuePriority.PRIORITY_HIGH).groupBy(JobQueuePriority.JOBS_GROUP_USER).requireNetwork());
	}

	@Override
	public void onAdded() {

	}

	@Override
	protected void onCancel() {

	}

	@Override
	public void onRun() throws Throwable {
        String result = OkHttpUtils.get(UrlUtils.GET_SERVICE_REQUESTS);
        OkHttpResponseData responseData = JSON.parseObject(result, OkHttpResponseData.class);
        EventBus.getDefault().post(new JobEvents.JobSuccess<>(JobEvents.GET_SERVICE_REQUESTS,responseData));
	}

	@Override
	protected RetryConstraint shouldReRunOnThrowable(Throwable throwable,
			int runCount, int maxRunCount) {
		EventBus.getDefault().post(new JobEvents.JobSuccess<>(JobEvents.GET_SERVICE_REQUESTS));
		return super.shouldReRunOnThrowable(throwable, runCount, maxRunCount);
	}
	
	

}
